//package com.icangya.lifePay;
//
//
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONObject;
//import com.icangya.Utils.CountUtils;
//import com.icangya.Utils.FormatUtil;
//import com.icangya.Value.StaticValue;
//import com.icangya.domain.LiefpayDO;
//import com.icangya.lifePay.utils.SignUtil;
//import com.icangya.lifePay.http.HttpClientUtil;
//import com.icangya.service.IFbWxSuitcaseService;
//import com.icangya.service.IFootUserService;
//import com.icangya.weixin.sdk.WXPayUtil;
//import org.joda.time.DateTime;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.*;
//
//import javax.annotation.Resource;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//import java.util.HashMap;
//import java.util.Random;
//import java.util.TreeMap;
//
//
///**
// * 微信公众号支付接口
// * 需要先调用微信网页授权接口获取open_id以及sub_open_id
// */
//@RestController
//@RequestMapping("/5")
//public class _5 {
//
//    @Resource
//    HttpClientUtil httpClientUtil;
//
//    @Autowired
//    private IFootUserService iFootUserService;
//
//    @Autowired
//    private IFbWxSuitcaseService iFbWxSuitcaseService;
//    @ResponseBody
//    @GetMapping
//    public String post(HttpServletResponse response,@RequestParam String money,@RequestParam String myopenid,@RequestParam String open_id, @RequestParam String sub_open_id)  {
//
//        com.icangya.domain.PayBean payBean = iFootUserService.getPaybeanByStatus();
//
//        TreeMap<String, String> map = new TreeMap<>();
//        map.put("app_id",payBean.getMchId());
//        map.put("method","openapi.payment.order.h5pay");
//        map.put("format","json");
//        map.put("sign_method","md5");
//        map.put("nonce", WXPayUtil.generateNonceStr());
//        map.put("version","1.0");
//
//
//        HashMap<String, Object> content = new HashMap<String, Object>();
//        content.put("merchant_order_sn",new DateTime().toString("yyyyMMdd")+ String.valueOf(new Random().nextInt(Integer.MAX_VALUE)));
//        content.put("open_id",open_id);
//        content.put("sub_open_id",sub_open_id);
//
//        int c = CountUtils.getCountInMinToMax(1,8);
//        System.out.println(Float.parseFloat(money)  +",,,"+ Float.parseFloat(String.valueOf(c))/100);
//        float fmoney  = Float.parseFloat(money)  + Float.parseFloat(String.valueOf(c))/100;
//        System.out.println(fmoney);
//
//        content.put("total_fee",fmoney);
//        content.put("store_id",payBean.getStoreId());
////        content.put("total_fee",0.01f);
////        content.put("store_id","3412");
////        content.put("cashier_id","");
//        map.put("biz_content", JSON.toJSONString(content));
//        String sign = SignUtil.createSign(map, payBean.getMchKey());
//        map.put("sign",sign);
//
//        String post = httpClientUtil.post(payBean.getRequestUrl(), JSON.toJSONString(map));
//
//
//        JSONObject jsonObject = JSONObject.parseObject(post);
//        String result_code = String.valueOf(jsonObject.get("result_code"));
//        if ("200".equals(result_code)){
//
//            String prepay_id = String.valueOf(jsonObject.getJSONObject("data").get("prepay_id"));
//            String order_sn = String.valueOf(jsonObject.getJSONObject("data").get("order_sn"));
//            String merchant_order_sn = String.valueOf(jsonObject.getJSONObject("data").get("merchant_order_sn"));
//
//            LiefpayDO liefpayDO = new LiefpayDO();
//            liefpayDO.setMoney(String.valueOf(fmoney));
//            liefpayDO.setOpenid(myopenid);
//            liefpayDO.setPrepayId(prepay_id);
//            liefpayDO.setOrderSn(order_sn);
//            liefpayDO.setMerchantOrderSn(merchant_order_sn);
//            liefpayDO.setCreateTime(FormatUtil.getStringDate());
//            liefpayDO.setPayStatus("0");
//
//            long syspayid = iFbWxSuitcaseService.saveLiefpayDO(liefpayDO);
//
//            if (syspayid > 0 && syspayid != 0){//fmoney
//                String payUrl = "http://shq-api-test.51fubei.com/paypage?prepay_id="+prepay_id+"&callback_url="+ StaticValue.WX.BASE_URL +"/6/liefpaynotity?strdata="+fmoney+"-"+merchant_order_sn;
//                System.out.println("`");
//                System.out.println(post);
//                System.out.println(payUrl);
//                try {
//                    response.sendRedirect(payUrl);
//                } catch (IOException e) {
//                    e.printStackTrace();
//                }
//            }
//
//        }
////        {
////            "result_message": "成功",
////                "data": {
////            "prepay_id": "wx2017061310090493ec0d235a0853792537",
////                    "order_sn": "20170613100903645492",
////                    "merchant_order_sn": "254678216387469387542389074230"
////        },
////            "result_code": 200
////        }
//        return post;
//    }
//
//}
